package java44th.group.controller.admin.history;

import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketSearchHistory;
import java44th.group.bean.admin.vo.BaseRespVo;
import java44th.group.service.admin.history.HistoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 21:06
 */
@RestController
@RequestMapping("admin/history")
public class HistoryController {

    @Autowired
    HistoryService historyService;

    // http://182.92.235.201:8083/admin/history/list?page=1&limit=20&userId=15&keyword=%E6%97%A5&sort=add_time&order
    // =desc
    @RequiresPermissions("*")
    @RequestMapping(value = "list",method = RequestMethod.GET)
    public BaseRespVo list(BasePageInfo basePageInfo,String userId,String keyword){
        Integer integerUserId = null;
        if (userId != null) {
            try {
                integerUserId = Integer.parseInt(userId);
            } catch (Exception e) {
                return BaseRespVo.error(400, "请输入正确的id值");
            }
        }

        CommonData<MarketSearchHistory> marketSearchHistoryCommonData  = historyService.list(basePageInfo,integerUserId,
                keyword);
        return BaseRespVo.ok(marketSearchHistoryCommonData);
    }

}
